package com.miplus.ccrm.core.service.commission;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.core.controller.vo.commission.*;
import com.miplus.ccrm.core.pojo.FiCommissionKpi;
import com.miplus.ccrm.core.pojo.FiCommissionKpiRatio;
import com.miplus.ccrm.core.service.commission.FiCommissionKpiRatioService;
import com.miplus.ccrm.core.mapper.FiCommissionKpiRatioMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author wangzl
* @description 针对表【fi_commission_kpi_ratio】的数据库操作Service实现
* @createDate 2025-03-03 15:37:10
*/
@Service
public class FiCommissionKpiRatioServiceImpl extends MPJBaseServiceImpl<FiCommissionKpiRatioMapper, FiCommissionKpiRatio>
    implements FiCommissionKpiRatioService{
    @Override
    public IPage<CommissionKpiRatioResVo> getCommissionKpiRatioList(CommissionKpiRatioListReqVo para)
    {
        return selectJoinListPage(new Page<>(para.getPageNum(),para.getPageSize()),
                CommissionKpiRatioResVo.class,
                new MPJLambdaWrapper<FiCommissionKpiRatio>()
                        .eq(StringUtils.isNotEmpty(para.getDisttag()),FiCommissionKpiRatio::getDisttag,para.getDisttag())
                        .ge(StringUtils.isNotEmpty(para.getStartDate()), FiCommissionKpiRatio::getStartdate,para.getStartDate())
                        .le(StringUtils.isNotEmpty(para.getEndDate()),FiCommissionKpiRatio::getStartdate,para.getEndDate())
                        .selectAll(FiCommissionKpiRatio.class)
                        .selectAs("fun_getnames('COMMISSION.KPI.TYPE',t.kpi_type)",CommissionKpiRatioResVo::getKpiTypeDesc)
                        .selectAs("fun_getnames('SORTING.QUEUE',t.disttag)", CommissionKpiRatioResVo::getDisttagDesc)
                        .orderByAsc(FiCommissionKpiRatio::getDisttag)
                        .orderByAsc(FiCommissionKpiRatio::getStartdate)
                        .orderByAsc(FiCommissionKpiRatio::getRank)
                        .orderByAsc(FiCommissionKpiRatio::getKpi1)
        );
    }
    @Override
    public CmdResVo addCommissionKpiRatio(String usrId, FiCommissionKpiRatio para){
        para.setId(null);
        para.setCrdt(new Date());
        para.setCrusr(usrId);
        save(para);
        return new CmdResVo( 1, para.getId().toString());
    }
    @Override
    public CmdResVo updateCommissionKpiRatio(String usrId, CommissionKpiRatioEditVo para)
    {
        if(ObjectUtils.isNull(para.getId()))
        {
            return new CmdResVo(-1, "参数错误");
        }
        FiCommissionKpiRatio fiCommissionKpiRatio = new FiCommissionKpiRatio();
        BeanUtils.copyProperties(para,fiCommissionKpiRatio);
        fiCommissionKpiRatio.setMddt(new Date());
        fiCommissionKpiRatio.setMdusr(usrId);
        updateById(fiCommissionKpiRatio);
        return new CmdResVo(1,"更新成功");
    }
    @Override
    public CmdResVo deleteCommissionKpiRatio(Integer id)
    {
        if(ObjectUtils.isNull(id))
        {
            return new CmdResVo(-1, "参数错误");
        }
        removeById(id);
        return new CmdResVo(1,"删除成功");
    }
}




